var path = require('path');
var webpack = require('webpack');
// 编译后自动打开浏览器
var OpenBrowserPlugin = require('open-browser-webpack-plugin');
// 产出html模板(后端渲染没有必要)
/*var HtmlWebpackPlugin = require("html-webpack-plugin");*/
// 单独样式文件
var ExtractTextPlugin = require("extract-text-webpack-plugin");
//用于屏蔽生产环境的警告输出
var InlineEnviromentVariablesPlugin = require('inline-environment-variables-webpack-plugin');
var node_modules = path.resolve(__dirname, 'node_modules');

/**
 * 标识开发环境和生产环境
 * @type {webpack.DefinePlugin}
 */
/*var definePlugin = new webpack.DefinePlugin({
 __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
 __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
 });*/

module.exports = {
    //后端渲染屏蔽热更新
    /*  devServer: {
     historyApiFallback: true,
     hot: true,
     inline: true,
     contentBase: './build',
     port: 8080,
     stats: { colors: true }
     },*/
    entry: {
        updateBrowser:'javascripts/hkfsUpdateBrowser.js',
        hkfsDetail:'javascripts/hkfsCommonDetail.js',
        hkfsMyAccount:'javascripts/hkfsMyAccount.js',
        hkfsCompute:'javascripts/hkfsCompute.js',
        specialModel:'javascripts/RenderSpecialModel.js',
        register:'javascripts/hkfsRegister.js',
        login:'javascripts/hkfsLogin.js',
        fundLineMap:'javascripts/renderFundLineMap.js',
        fundDetail:'javascripts/hkfsFundDetail.js',
        productDetail:'javascripts/hkfsProductDetail.js',
        viewPoint:'javascripts/hkfsViewPoint.js',
        hkfsMap:'javascripts/renderMap.js',
        model:'javascripts/RenderModel.js',
        index:'javascripts/hkfsHome.js',
        about:'javascripts/hkfsAbout.js',
        products:'javascripts/hkfsProducts.js',
        detail:'javascripts/detailtest.js',
        vendor: ['react', 'react-dom','console-polyfill']/*兼容文件和react一起独立打包*/
    },
    output: {
        path: 'public/build',
        filename: '[name].bundle.js',
        /*     filename: '[name]-[chunkhash:6].js',*///添加md5后缀
        publicPath: '/'
    },
    resolve: {
        root:__dirname,
        extension: ['', '.jsx', '.js', '.json'],
        // 提高webpack搜索的速度
        alias: { }
    },
    //生产环境需改为false
    devtool: 'false',
    'display-error-details': false,
    // 使用externals可以将react分离，然后用<script>单独将react引入
    externals: [],
    module: {
        loaders: [
            {
                test: /\.js[x]?$/,
                loaders: [ 'babel'],
                exclude: path.resolve(__dirname, 'node_modules')
            },
            {
                test: /\.css/,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader")
            },
            {
                test: /\.less/,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
            },
            {
                test: /\.(png|jpg)$/,
                loader: 'url?limit=8192&name=../images/pc/[name].[ext]'
            },
            {
                test: /\.(woff|woff2|ttf|svg|eot)(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url?limit=10000"
            }
        ],
        //此配置文件不兼容ie，无须再进行es3转换
       /* postLoaders: [
            {
                test: /\.js[x]?$/,
                loaders: ['es3ify-loader']
            }
        ]*/
    },
    plugins: [
  /*      new webpack.HotModuleReplacementPlugin(),*/
        /*弃用jquery，改用轻量级的ajax框架reqwest*/
       // new webpack.ProvidePlugin({$: 'jquery'}),//使jquery变成全局变量，无须require('jquery')
        new webpack.ProvidePlugin({reqwest: 'reqwest'}),//使reqwest变成全局变量，无须require
        new webpack.NoErrorsPlugin(),
        /*    definePlugin,*/
        /*此处用于将公共的库文件抽出，输出的文件需要放在最前方，但由于兼容旧版本浏览器的操作需要在所有js文件之前引入，无法使用该功能*/
        new webpack.optimize.CommonsChunkPlugin('vendor', '[name].bundle.js'),
        /*此处用于自动生成html文件，由于采用后端渲染，弃用*/
        /*    new HtmlWebpackPlugin({
         title: 'your app title',
         template: './app/index.html',
         }),*/
        new OpenBrowserPlugin({ url: 'http://localhost:3000' }),
        new ExtractTextPlugin("[name].style.css", {
            allChunks: true,
            disable: false
        }),
        new webpack.DefinePlugin({
            'process.env':{
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new InlineEnviromentVariablesPlugin()
    ]
};

